Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add useNetworks and useNetworksRelationship hooks #1297

Merged

Conversation

chrstph-dvx
Copy link
Contributor

Summary

See #1295

Steps to test

There should be no change visible to the users

@chrstph-dvx chrstph-dvx self-assigned this Nov 16, 2023
@chrstph-dvx chrstph-dvx linked an issue Nov 16, 2023 that may be closed by this pull request
@cla-bot cla-bot bot added the cla-signed label Nov 16, 2023
Copy link

vercel bot commented Nov 16, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
arbitrum-token-bridge ✅ Ready (Inspect) Visit Preview Dec 7, 2023 3:51pm

Copy link
Member

@spsjvc spsjvc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments, things look good so far, but the hooks aren't used anywhere?

It's fine if we want to split the effort into multiple PRs, but then let's create another one on top of this one that actually leverages the hooks so we can test it.

Comment on lines 125 to 127
function isValidNumber(value: number) {
return !Number.isNaN(value)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems generic enough that it should be in a more common util file?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about this one, I would move it once it's needed somewhere else. It's only here because the query param library might return null or undefined for a number, I'm not sure we have this case anywhere else.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a strong opinion but the name isValidNumber and what it does in the fn are totally reusable in any other functions when we want to check isNaN

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it here until it's needed elsewhere

@@ -97,6 +108,55 @@ export const AmountQueryParam = {
}
}

// Parse chainId to ChainQueryParam or ChainId for orbit chain
function encodeChainQueryParam(chainId: number | null | undefined) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better be explicit and type the return type too

spsjvc
spsjvc previously approved these changes Dec 7, 2023
Copy link
Member

@spsjvc spsjvc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@spsjvc spsjvc changed the title feat: Add useNetworks and useNetworksRelationship hooks feat: add useNetworks and useNetworksRelationship hooks Dec 7, 2023
})
})
describe('when `destinationChainId` is valid', () => {
it('and `sourceChainId` is valid should not do anything', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so right now i can read this line and understand it properly because I've been looking at this PR

but i worry down the line this doesn't have a very high readability

plus, both source chain id and destination chain id should be equally important conditions, so i would do this instead:

describe('when `destinationChainId` is valid and `sourceChainId` is valid', () => {
    it('should not do anything', () => {}
}
describe('when `destinationChainId` is valid and `sourceChainId` is invalid', () => {
    it('should set `sourceChainId`', () => {}
}
...

There are 2 vars with 3 possible values each (undefined/valid/invalid) so there should be 3x3 = 9 cases here
i see them all in place in this file but they should have parallel status given that the 2 vars' initial values have no dependency on each other

Comment on lines +48 to +55
const resultWithSepoliaOrbitChain = sanitizeQueryParams({
sourceChainId: 2222,
destinationChainId: ChainId.ArbitrumSepolia
})
expect(resultWithSepoliaOrbitChain).toEqual({
sourceChainId: 2222,
destinationChainId: ChainId.ArbitrumSepolia
})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

other than testnet, i'd also add a test for orbit <-> arb one and orbit <-> arb nova to make sure it doesn't only go to arb one and never to arb nova

Copy link
Member

@fionnachan fionnachan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@spsjvc spsjvc enabled auto-merge (squash) December 7, 2023 16:00
@spsjvc spsjvc merged commit 755c989 into master Dec 7, 2023
23 of 24 checks passed
@spsjvc spsjvc deleted the 1296-add-usenetworks-and-usenetworksrelationship-to-our-codebase branch December 7, 2023 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add useNetworks and useNetworksRelationship to our codebase
3 participants